package com.ld.security.auth.common.impl;

import com.ld.security.auth.common.feign.LogFeign;
import com.ld.security.auth.common.po.ApiLogPo;
import com.ld.security.auth.common.util.AuthUtil;
import com.ld.security.common.core.base.po.EntitysPo;
import com.ld.security.common.core.base.queue.SuperQueue;
import lombok.extern.java.Log;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.LinkedList;
import java.util.List;


@Slf4j
public class ApiLogQueueImpl implements SuperQueue<ApiLogPo> {

    private List<ApiLogPo> list = new LinkedList<>();

    @Autowired
    private LogFeign logFeign;

    @Override
    public void push(ApiLogPo entity) {
        list.add(entity);
    }

    /**
     * 30秒同步一次
     */
    @Scheduled(cron = "0/30 * * * * ?")
    public void sendMsg(){

        if(list.size() > 0){
            try{
                EntitysPo po =  new EntitysPo<>();
                po.setList(list);
                logFeign.push(po);
                list.clear();
            }catch (Exception e){
                //日志记录异常
                e.printStackTrace();
            }

        }

    }


}
